package cn.virens.common.boot.filter;

import jakarta.servlet.Filter;
import org.springframework.beans.BeansException;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class FilterRegistrationBeanAware<T extends Filter> extends FilterRegistrationBean<T> implements ApplicationContextAware {
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if (getFilter() instanceof ApplicationContextAware contextAware) {
            contextAware.setApplicationContext(applicationContext);
        }
    }
}
